document.addEventListener('DOMContentLoaded', function () {
  var likesbtn = document.getElementById('likes-btn')
  likesbtn.addEventListener('click', function () {
    fetch(
      '/images/likes/' + likesbtn.dataset.imageid,
      { method: 'POST', body: {} }
    ).then(response => response.json())
      .then(resp => {
        console.log(resp)
        // var xhr = new XMLHttpRequest()
        // xhr.open('post', '/images/likes/' + likesbtn.dataset.imageid)
        // xhr.setRequestHeader('Content-type', 'application/x-www-form/urlencoded')
        // xhr.send('')
        // xhr.onreadystatechange = function () {
        //   if (xhr.readyState == 4 && xhr.status == 200) {
        //     var content = xhr.responseText
        //     console.log(content)
        //     var jsonArr = JSON.parse(content)
        //     console.log(jsonArr)
        //     console.log(jsonArr.likes)
        //     likesbtn.textContent = jsonArr.likes
        //   }
        // }
        var likesNum = document.getElementById('likesnum')
        likesNum.textContent = resp.likes
        
        
      })

    
  })
  
})

